package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizRaffleActivityPrize;
import com.member.shop.domain.SysBizRafflePrize;
import com.member.shop.service.ISysBizRaffleActivityPrizeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 抽奖活动奖品对应关系Controller
 *
 * @author thomas
 * @date 2024-03-15
 */
@RestController
@RequestMapping("shop/raffle/activityPrize")
public class SysBizRaffleActivityPrizeController extends BaseController {
    @Resource
    private ISysBizRaffleActivityPrizeService sysBizRaffleActivityPrizeService;

    private void setTenantId(SysBizRaffleActivityPrize sysBizRaffleActivityPrize) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizRaffleActivityPrize.setTenantId(tenantId);
        }
    }

    /**
     * 查询抽奖活动奖品对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('raffle:activityPrize:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizRaffleActivityPrize sysBizRaffleActivityPrize) {
        startPage();
        setTenantId(sysBizRaffleActivityPrize);
        List<SysBizRaffleActivityPrize> list = sysBizRaffleActivityPrizeService.selectSysBizRaffleActivityPrizeList(sysBizRaffleActivityPrize);
        return getDataTable(list);
    }

    /**
     * 导出抽奖活动奖品对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('raffle:activityPrize:export')")
    @Log(title = "抽奖活动奖品对应关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizRaffleActivityPrize sysBizRaffleActivityPrize) {

        setTenantId(sysBizRaffleActivityPrize);
        List<SysBizRaffleActivityPrize> list = sysBizRaffleActivityPrizeService.selectSysBizRaffleActivityPrizeList(sysBizRaffleActivityPrize);
        ExcelUtil<SysBizRaffleActivityPrize> util = new ExcelUtil<SysBizRaffleActivityPrize>(SysBizRaffleActivityPrize.class);
        util.exportExcel(response, list, "抽奖活动奖品对应关系数据");
    }

    /**
     * 获取抽奖活动奖品对应关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('raffle:activityPrize:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizRaffleActivityPrizeService.selectSysBizRaffleActivityPrizeById(id));
    }

    /**
     * 新增抽奖活动奖品对应关系
     */
    @PreAuthorize("@ss.hasPermi('raffle:activityPrize:add')")
    @Log(title = "抽奖活动奖品对应关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizRaffleActivityPrize sysBizRaffleActivityPrize) {
        return toAjax(sysBizRaffleActivityPrizeService.insertSysBizRaffleActivityPrize(sysBizRaffleActivityPrize));
    }

    /**
     * 修改抽奖活动奖品对应关系
     */
    @PreAuthorize("@ss.hasPermi('raffle:activityPrize:edit')")
    @Log(title = "抽奖活动奖品对应关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizRaffleActivityPrize sysBizRaffleActivityPrize) {
        return toAjax(sysBizRaffleActivityPrizeService.updateSysBizRaffleActivityPrize(sysBizRaffleActivityPrize));
    }

    /**
     * 删除抽奖活动奖品对应关系
     */
    @PreAuthorize("@ss.hasPermi('raffle:activityPrize:remove')")
    @Log(title = "抽奖活动奖品对应关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizRaffleActivityPrizeService.deleteSysBizRaffleActivityPrizeByIds(ids));
    }
}
